package site.wlwsjsx.iot_backend.service;

import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import site.wlwsjsx.iot_backend.service.ReceiveService;

@SpringBootTest
public class ReceiveServiceTest {
    @Resource
    ReceiveService receiveService;

    @Test
    void test() {
        String msg = "{" +
                "\"notifyType\":\"property\"," +
                "\"productId\":\"3HSBa0ZB1R\"," +
                "\"messageType\":\"notify\"," +
                "\"deviceName\":\"ESP_01\"," + // 工位编号，将赋值给 workstationCode
                "\"data\":{" +
                "\"id\":\"1758561880137\"," + // 数据ID
                "\"params\":{" +
                // 温度：含time（用于生成createTime）和value
                "\"CurrentTemperature\":{" +
                "\"time\":1758561883356," +
                "\"value\":34.5" +
                "}," +
                // 湿度
                "\"RelativeHumidity\":{" +
                "\"time\":1758561883354," +
                "\"value\":23.8" +
                "}," +
                // 火焰强度（0.0表示无火焰，符合正常场景）
                "\"FlameScope\":{" +
                "\"time\":1758561883355," +
                "\"value\":0.0" +
                "}," +
                // 热度（28.3%，模拟常温）
                "\"HeatScope\":{" +
                "\"time\":1758561883357," +
                "\"value\":28.3" +
                "}," +
                // 光照强度（76.5%，模拟室内正常光照）
                "\"LightLuxValue\":{" +
                "\"time\":1758561883358," +
                "\"value\":76.5" +
                "}," +
                // 灯光状态（1=开启）
                "\"LightStatus\":{" +
                "\"time\":1758561883359," +
                "\"value\":1" +
                "}," +
                // 电源状态（1=通电）
                "\"PowerStatus\":{" +
                "\"time\":1758561883360," +
                "\"value\":1" +
                "}," +
                // 1号继电器（0=断开）
                "\"RelayNum1Status\":{" +
                "\"time\":1758561883361," +
                "\"value\":0" +
                "}," +
                // 2号继电器（1=闭合）
                "\"RelayNum2Status\":{" +
                "\"time\":1758561883362," +
                "\"value\":1" +
                "}," +
                // 烟雾浓度（5.2%，无烟雾）
                "\"SmokeScope\":{" +
                "\"time\":1758561883363," +
                "\"value\":5.2" +
                "}," +
                // UserId（模拟存在的用户，用于关联查询curUserId）
                "\"UserId\":{" +
                "\"time\":1758561883364," +
                "\"value\":\"2230090210\"" +
                "}" +
                "}" +
                "}" +
                "}";
        receiveService.dealMessageFromJson(msg);
    }
}
